package com.zzy.blog.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.zzy.blog.dao.BaseDao;
import com.zzy.blog.dao.LoginDao;
import com.zzy.blog.dao.pojo.Memory;
import com.zzy.blog.dao.pojo.User;

public class LoginDaoImpl extends BaseDao implements LoginDao {
	
	public boolean checkUser(User user) {
		Session session = sessionFactory.openSession();
		Query query = session.createSQLQuery("select * from user where name='" + user.getName() + "' and password='" + user.getPassword() + "'");
		return query.list().size() != 0;
	}

	public List<Memory> getMemory() {
		Session session = sessionFactory.openSession();
		Query query = session.createSQLQuery("select * from Memory");
		return query.list();
	}

	public void save(Memory m) {
		Session session = sessionFactory.openSession();
		Transaction tx = session.beginTransaction();
		session.save(m);
		tx.commit();
		session.close();
	}
	
	public void save(User u) {
		Session session = sessionFactory.openSession();
		Transaction tx = session.beginTransaction();
		session.save(u);
//		tx.commit();
		session.close();
	}
}
